<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet"href="/css/plat-style.css">
    <style>
        thead tr th{text-align: center!important;font-weight: bold!important;}
        tr td{text-align: center!important;}
        .layui-table img {
            width: auto;
            height: auto;
            max-width: 100% !important;
            max-height: 100%;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form action="/icon/classification" id="seachFrom" class="layui-form">
                    <div class="layui-card-body">
                        <div class="layui-container" style="padding-bottom: 50px">
                            <div class="layui-col-md12">
                                <%--<div class="layui-col-md4">
                                    <div class="layui-col-sm6 layui-col-sm-offset2">
                                        <select class="select" name="position">
                                            <option value="">请选择应用位置</option>
                                            <c:forEach items="${iconList}" var="i">
                                                <option value="${i.position}" ${classify.position==i.position?'selected':''}>${i.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>--%>
                                <div class="layui-col-md4">
                                    <div class="layui-col-sm8">
                                        <%--<button class="layui-btn" type="submit">查询</button>--%>
                                        <button class="layui-btn layui-btn-warm editThis" type="button" data-id="">添加分类图</button>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12">&nbsp;</div>
                        </div>
                        <hr>
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>图标</th>
                                <th>分类别名</th>
                                <th>跳转的分类</th>
                                <th>排序</th>
                                <th>事件类型</th>
                                <th>图标位置</th>
                                <th>是否显示</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${pageInfo.records}" var="l">
                                <tr>
                                    <td>
                                        <img src="${l.icon}" style="width: 50px;height: 50px;">
                                    </td>
                                    <td>${l.name}</td>
                                    <td>
                                        <c:if test="${l.url != ''}">
                                            <span class="green">${l.classifyName} </span> (ID: ${l.url})
                                        </c:if>
                                    </td>
                                    <td>${l.sort}</td>
                                    <td>${l.eventName}</td>
                                    <td>
                                        <c:if test="${l.position==1}">APP</c:if>
                                        <c:if test="${l.position==2}">小程序</c:if>
                                        <c:if test="${l.position==3}">微信</c:if>
                                        <c:if test="${l.position==4}">PC</c:if>
                                    </td>
                                    <td>
                                        <c:if test="${l.display==1}"><span class="green">是</span></c:if>
                                        <c:if test="${l.display==0}"><span class="red">否</span></c:if>
                                    </td>
                                    <td>
                                        <button data-id="${l.id}" data-type="editThis" type="button"
                                                class="layui-btn layui-btn-sm layui-btn-primary editThis">编辑</button>
                                        <c:if test="${l.display==0}">
                                            <button data-id="${l.id}" data-status="1" data-type="updateThis" type="button"
                                                    class="layui-btn layui-btn-sm layui-btn updateThis">显示</button>
                                        </c:if>
                                        <c:if test="${l.display==1}">
                                            <button data-id="${l.id}" data-status="0" data-type="updateThis" type="button"
                                                    class="layui-btn layui-btn-sm layui-btn-warm updateThis">隐藏</button>
                                        </c:if>
                                        <button data-id="${l.id}" data-type="delThis" type="button"
                                                class="layui-btn layui-btn-sm layui-btn-danger delThis">删除</button>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        <div class="test-table-reload-btn" style="margin-top: 10px;">
                            <%@include file="../paging.jsp" %>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$,
            form = layui.form,
            element = layui.element,
            layer = layui.layer;
        form.render();
        element.render();

        var active = {
            editThis: function (id) {
                layer.open({
                    title:'新增/编辑分类图标',
                    type: 2,
                    area: ['600px', '500px'],
                    content: '/icon/classificationEdit?id='+id
                });
            },
            updateThis:function(id,url,status){
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: url,
                        data: {'id': id,'display':status},
                        dataType: "json",
                        type: "post",
                        success: function (status) {
                            layer.msg(status);
                            if (status) {
                                layer.msg('操作成功', {icon: 1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg('操作失败', {icon: 2})
                            }
                        }
                    })
                });
            },
            delThis:function (id,url) {
                layer.confirm('确定删除吗？', function(){
                    delThis(id,url);
                });
            }
        };
        $('.editThis').on('click', function(){
            var id = $(this).data('id');
            var type = 'editThis';
            active[type] && active[type].call(this,id);
        });
        $('.updateThis').on('click',function () {
            var id = $(this).data('id');
            var status = $(this).data('status');
            var type = $(this).data('type');
            var url = "/icon/handleClassificationStatus";
            active[type] && active[type].call(this,id,url,status);
        });
        $('.delThis').on('click',function () {
            var delType = $(this).data('type');
            var id = $(this).data('id');
            var url = "/icon/deleteClassification";
            active[delType] && active[delType].call(this,id,url);
        });
    });
</script>
</body>
</html>